import React from 'react';
import { Modal as Modal_ } from 'antd';
import { ModalFuncProps } from 'antd/es/modal';

/**
 * 弹窗函数
 */
export const {
  confirm, // 对话确认框
} = Modal_;

interface IModalConfirmProps extends ModalFuncProps {
  children: JSX.Element;
}

/**
 * 对话确认框
 */
export class ModalConfirm extends React.Component<IModalConfirmProps> {
  onClick = () => {
    const { children, ...props } = this.props;
    confirm(props);
  };

  render() {
    return React.cloneElement(this.props.children, { onClick: this.onClick });
  }
}
